/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.buzzwords.model;

import com.buzzwords.clientside.model.ClientBuzzword;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * A Buzzword is a frequently used term they have different meanings in different
 * contexts. Buzzword has many locales
 * 
 * @author potlow
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class Buzzword {

    static public String BUZZWORD_LOCALES = "buzzword.locales";

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    // Buzzword
    @Persistent
    private String word = "";

    // Different locations buzzword exists in
    @Persistent(mappedBy="buzzword")
    private List<Locale> locales = new ArrayList<Locale>();

    // Creation date of buzzword
    @Persistent
    private Date creationDate;

    /**
     * Constructor takes word and creating user
     * @param word Buzzword
     * @param user Creating user
     */
    public Buzzword(String word) {
        this.word = word;
        this.creationDate = new Date();
    }

    /**
     * Default constructor
     */
    public Buzzword() {
    }

    public List<Locale> getLocales() {
        return locales;
    }

    public void setLocales(List<Locale> locales) {
        this.locales = locales;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Key getKey() {
        return key;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public ClientBuzzword getClientBuzzword() {
        ClientBuzzword clientBuzzword = new ClientBuzzword();
        clientBuzzword.setWord(word);
        clientBuzzword.setKey(KeyFactory.keyToString(key));

        for(Locale locale : locales)
            clientBuzzword.getLocales().add(locale.getClientLocale());

        return clientBuzzword;
    }
    
}
